package com.api.shopapi.mapper;

import com.api.shopapi.entity.DisableLevel;
import com.api.shopapi.entity.DiseaseType;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface DisableLevelMapper {

    @Insert("insert into disable_level" +
            " (" +
            "disableLevelCode," +
            "Name," +
            "Sort," +
            "Status," +
            "GovernmentCode," +
            "InstitutionCode" +
            ") values " +
            "(" +
            "#{disableLevel.disableLevelCode}," +
            "#{disableLevel.Name}," +
            "#{disableLevel.Sort}," +
            "#{disableLevel.Status}," +
            "#{disableLevel.GovernmentCode}," +
            "#{disableLevel.InstitutionCode})")
    int insert(@Param("disableLevel") DisableLevel disableLevel);


    @Update("update disable_level" +
            " set" +
            " Name=#{disableLevel.Name}," +
            "Sort=#{disableLevel.Sort}," +
            "Status=#{disableLevel.Status}," +
            "InstitutionCode=#{disableLevel.InstitutionCode} " +
            "where disableLevelCode=#{disableLevel.disableLevelCode}")
    int update(@Param("disableLevel") DisableLevel disableLevel);

    @Select("select * from disable_level where disableLevelCode=#{disableLevelCode} limit 1")
    DisableLevel getByDisableLevelCode(@Param("disableLevelCode") String disableLevelCode);


    @Select("select * from disable_level where disableTypeName=#{disableTypeName} limit 1")
    DisableLevel getByDisableLevelName(@Param("disableTypeName") String disableTypeName);


    @Select("<script>" +
            "select * from disable_level " +
            " where institutionCode=#{institutionCode}" +
            " order by sort desc" +
            "</script>")
    List<DisableLevel> listByInsCode(@Param("institutionCode") String institutionCode);


    @Select("<script>" +
            "select * from disable_level " +
            " where institutionCode in (SELECT distinct institutionCode FROM institution where governmentCode=#{governmentCode})" +
            " order by sort desc" +
            "</script>")
    List<DisableLevel> listByGovCode( @Param("governmentCode") String governmentCode);


}
